//
//  SubjectTableViewCell.m
//  FairyDream
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 dreams. All rights reserved.
//

#import "SubjectTableViewCell.h"
#import "ThreeImageCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@interface SubjectTableViewCell() <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (nonatomic, retain) UICollectionViewFlowLayout *layout;
@end
@implementation SubjectTableViewCell

- (void)dealloc
{
    [_customArray release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.customArray = [NSMutableArray array];
        [self createCollectionView];
    }
    return self;
}

- (void)createCollectionView
{
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
    
    lable.text = @"发现下一站";
    [self addSubview:lable];
    
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    
    _layout.minimumInteritemSpacing = 10;
    _layout.minimumLineSpacing = 10;
    
    self.collecView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, 375, 300) collectionViewLayout:_layout];
    
    _collecView.backgroundColor = [UIColor whiteColor];
    _collecView.delegate = self;
    _collecView.dataSource = self;
    [_collecView registerClass:[ThreeImageCollectionViewCell class] forCellWithReuseIdentifier:@"three"];
    [self.contentView addSubview:_collecView];
    
    [_layout release];
    [_collecView release];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _customArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ThreeImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"three" forIndexPath:indexPath];
    if (_customArray.count != 0) {
        NSDictionary *dic = [_customArray objectAtIndex:indexPath.item];
        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"photo"]] placeholderImage:nil];
    }
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item == 0) {
        _layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 180);
        return _layout.itemSize;
    }
    else
    {
        _layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width / 2.057, 100);
        return _layout.itemSize;
    }
}

@end
